﻿using System.Linq;
using LazyFieldDemo.Models;
using Orchard.Data;
using Orchard.DisplayManagement.Implementation;

namespace LazyFieldDemo.Shapes {
    public class EditorShapes : ShapeDisplayEvents {
        private readonly IRepository<Country> _countryRepository;
        public EditorShapes(IRepository<Country> countryRepository) {
            _countryRepository = countryRepository;
        }

        public override void Displaying(ShapeDisplayingContext context) {

            switch (context.ShapeMetadata.Type) {
                case "CountryDropDownList":
                    context.Shape.Countries = _countryRepository.Table.OrderBy(x => x.Name).ToList();
                    break;
            }
        }
    }
}